package com.driver.fordriver.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.driver.fordriver.R;
import com.driver.fordriver.fragment.BaseFragment;
import com.driver.fordriver.fragment.MapFragment;
import com.driver.fordriver.fragment.SettingFragment;
import com.driver.fordriver.fragment.ShareFragment;

import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;

import solid.ren.skinlibrary.base.SkinBaseActivity;
import solid.ren.skinlibrary.loader.SkinInflaterFactory;


public class ViewActivity extends SkinBaseActivity {

    private ViewPager viewPager;

    private String[] titles;
    private ArrayList<Fragment> fragments;
    private SkinInflaterFactory factory;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view);
        factory=new SkinInflaterFactory(this);
        init();
    }

    public SkinInflaterFactory getFactory() {
        return factory;
    }

    private void init() {
        titles=getResources().getStringArray(R.array.titiles);
        fragments = new ArrayList<Fragment>();
        fragments.add(new ShareFragment());
        fragments.add(new BaseFragment());
        fragments.add(new MapFragment());
        fragments.add(new SettingFragment());
        MyFragmentAdapter adapter= new MyFragmentAdapter(getSupportFragmentManager());
        viewPager= (ViewPager) findViewById(R.id.viewpager);
        viewPager.setAdapter(adapter);
    }

    private class MyFragmentAdapter extends FragmentPagerAdapter{

        public MyFragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return 4;
        }
    }

}
